<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>循环遍历精灵图</title>
    <style>
        li {
            list-style: none;
        }
        .box {
            width: 200px;
            margin: 100px auto;
        }
        .box li {
            float: left;
            height: 24px;
            width: 24px;
            margin-left: 20px;
            margin-bottom: 20px;
            background: url(images/sprite.png) no-repeat;
        }
    </style>
</head>
<body>
    <div class="box">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </div>
    <script>
        var lis = document.querySelectorAll('li');
        for (var i = 0; i < lis.length; i++) {
            var y = i * 44;
            lis[i].style.backgroundPosition = '0 -' + y + 'px'; 
        }
    </script>
</body>
</html>